package com.zry.yard.ui.activity

import android.annotation.SuppressLint
import com.zry.yard.R
import com.zry.yard.been.FlowCodeBean
import com.zry.yard.been.ResultBean
import com.zry.yard.databinding.ActivityCirculationCodeInfoBinding
import com.zry.yard.retrofit.HttpServer
import com.zry.yard.retrofit.ShowUserView
import com.zry.yard.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_circulation_code_info.*
import kotlinx.android.synthetic.main.common_title.*

class CirculationCodeInfoActivity : BaseActivity(), ShowUserView {
    private var title = ""
    private var longCode = ""
    private var circulationCodeInfoBinding: ActivityCirculationCodeInfoBinding? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_circulation_code_info
    }

    override fun initData() {
        title = intent.getStringExtra("title")
        longCode = intent.getStringExtra("longCode")
        titleCenterText.text = "追溯码详情"
        commonLeftLinearLayout.setOnClickListener { finish() }

        circulationCodeInfoBinding = viewDataBinding as ActivityCirculationCodeInfoBinding

        HttpServer(this).getFlowCodeByCodeInfo(longCode, this)
    }

    @SuppressLint("SetTextI18n")
    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            40 -> {
                val resultData = data as ResultBean<FlowCodeBean>
                if (resultData.State == "1") {
                    circulationCodeInfoBinding?.flowCodeBean = resultData.ResultData
                    when (resultData.ResultData.FlowLevel) {
                        "1" -> circulationFlowCode.text = "单码入库"
                        "2" -> circulationFlowCode.text = "二级码入库"
                        "3" -> circulationFlowCode.text = "三级码入库"
                        "0" -> circulationFlowCode.text = ""
                    }
                    when (resultData.ResultData.StateID) {
                        "1" -> circulationPutStorageMode.text = "手动入库"
                        "2" -> circulationPutStorageMode.text = "自动入库"
                        "0" -> circulationPutStorageMode.text = ""
                    }
                    when (resultData.ResultData.StoreType) {
                        "1" -> circulationPutStorageType.text = "单码入库"
                        "2" -> circulationPutStorageType.text = "二级码入库"
                        "3" -> circulationPutStorageType.text = "三级码入库"
                        "0" -> circulationPutStorageType.text = ""
                    }
                    when (resultData.ResultData.OutStateID) {
                        "1" -> circulationOutTraceType.text = "手动出库"
                        "2" -> circulationOutTraceType.text = "自动出库"
                        "0" -> circulationOutTraceType.text = ""
                    }
                    when (resultData.ResultData.OutType) {
                        "1" -> circulationOutTraceStateType.text = "单码出库"
                        "2" -> circulationOutTraceStateType.text = "二级码出库"
                        "3" -> circulationOutTraceStateType.text = "三级码出库"
                        "0" -> circulationOutTraceStateType.text = ""
                    }

                    expiryDateTV.text=resultData.ResultData.ExpiryDate+"月"

                } else {
                    toast(resultData.Message)
                }
            }
        }
    }
}
